<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, viewport-fit=cover">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="apple-mobile-web-app-title" content="沙盘控制器">
    <meta name="mobile-web-app-capable" content="yes">
    <title>沙盘控制器 - 手机端</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Arial', sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            height: 100vh;
            overflow: hidden;
            -webkit-touch-callout: none;
            -webkit-user-select: none;
            user-select: none;
            -webkit-tap-highlight-color: transparent;
        }

        .container {
            display: flex;
            flex-direction: column;
            height: 100vh;
            padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
        }

        .header {
            background: rgba(255, 255, 255, 0.15);
            backdrop-filter: blur(15px);
            padding: 20px;
            color: white;
            text-align: center;
            border-bottom: 1px solid rgba(255, 255, 255, 0.2);
        }

        .title {
            font-size: 24px;
            font-weight: bold;
            margin-bottom: 10px;
        }

        .status {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 10px;
            font-size: 16px;
        }

        .status-indicator {
            width: 16px;
            height: 16px;
            border-radius: 50%;
            background: #ff4444;
            transition: background 0.3s;
        }

        .status-indicator.connected {
            background: #44ff44;
        }

        .main-content {
            flex: 1;
            padding: 20px;
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
        }

        .control-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 15px;
            margin-bottom: 25px;
        }

        .control-section {
            background: rgba(255, 255, 255, 0.15);
            backdrop-filter: blur(15px);
            border-radius: 20px;
            padding: 20px;
            color: white;
        }

        .control-section.full-width {
            grid-column: 1 / -1;
        }

        .section-title {
            font-size: 18px;
            font-weight: bold;
            margin-bottom: 15px;
            text-align: center;
            color: #fff;
        }

        .control-button {
            width: 100%;
            min-height: 50px;
            padding: 15px;
            margin-bottom: 12px;
            background: rgba(255, 255, 255, 0.2);
            border: none;
            border-radius: 15px;
            color: white;
            font-size: 16px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
        }

        .control-button:hover {
            background: rgba(255, 255, 255, 0.3);
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
        }

        .control-button:active {
            transform: translateY(0);
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        .control-button.primary {
            background: rgba(76, 175, 80, 0.8);
        }

        .control-button.danger {
            background: rgba(244, 67, 54, 0.8);
        }

        .control-button.warning {
            background: rgba(255, 152, 0, 0.8);
        }

        .slider-container {
            margin-bottom: 20px;
        }

        .slider-label {
            display: block;
            margin-bottom: 10px;
            font-size: 16px;
            font-weight: bold;
            text-align: center;
        }

        .slider {
            width: 100%;
            height: 12px;
            border-radius: 6px;
            background: rgba(255, 255, 255, 0.3);
            outline: none;
            -webkit-appearance: none;
        }

        .slider::-webkit-slider-thumb {
            -webkit-appearance: none;
            appearance: none;
            width: 28px;
            height: 28px;
            border-radius: 50%;
            background: #fff;
            cursor: pointer;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        }

        .coordinates {
            background: rgba(0, 0, 0, 0.2);
            padding: 15px;
            border-radius: 15px;
            font-family: monospace;
            font-size: 14px;
            text-align: center;
        }

        .mode-switcher {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 10px;
            margin-top: 10px;
        }

        .mode-button {
            padding: 12px 16px;
            border: 2px solid rgba(255, 255, 255, 0.3);
            background: rgba(255, 255, 255, 0.1);
            color: white;
            border-radius: 12px;
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s ease;
            backdrop-filter: blur(10px);
        }

        .mode-button:hover {
            background: rgba(255, 255, 255, 0.2);
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        }

        .mode-button.active {
            background: rgba(255, 255, 255, 0.25);
            border-color: rgba(255, 255, 255, 0.5);
            box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
        }

        .drawing-tools {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 10px;
            margin-top: 10px;
        }

        .gallery-tools {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 10px;
            margin-top: 10px;
        }

        .gallery-tools .control-button {
            font-size: 13px;
            padding: 10px 12px;
        }

        .gallery-tools .control-button:last-child {
             grid-column: 1 / -1;
         }

        .gallery-navigation {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 10px;
            margin-top: 15px;
        }

        .gallery-navigation .control-button {
            font-size: 14px;
            padding: 12px 16px;
            background: rgba(33, 150, 243, 0.8);
            transition: all 0.3s ease;
        }

        .gallery-navigation .control-button:hover {
            background: rgba(33, 150, 243, 1);
            transform: translateY(-2px);
        }

        .gallery-navigation .control-button:disabled {
            background: rgba(255, 255, 255, 0.1);
            color: rgba(255, 255, 255, 0.5);
            cursor: not-allowed;
            transform: none;
        }

         .tool-button {
            aspect-ratio: 1;
            background: rgba(255, 255, 255, 0.2);
            border: none;
            border-radius: 15px;
            color: white;
            font-size: 24px;
            cursor: pointer;
            transition: all 0.3s;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .tool-button:hover {
            background: rgba(255, 255, 255, 0.3);
            transform: scale(1.05);
        }

        .tool-button.active {
            background: rgba(76, 175, 80, 0.8);
        }

        .virtual-trackpad {
            height: 200px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 20px;
            border: 2px dashed rgba(255, 255, 255, 0.3);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 16px;
            color: rgba(255, 255, 255, 0.7);
            touch-action: none;
            position: relative;
            overflow: hidden;
        }

        .trackpad-cursor {
            position: absolute;
            width: 20px;
            height: 20px;
            background: rgba(255, 255, 255, 0.8);
            border-radius: 50%;
            pointer-events: none;
            transition: all 0.1s;
            transform: translate(-50%, -50%);
        }

        .config-btn {
            background: rgba(255, 255, 255, 0.2);
            border: none;
            border-radius: 50%;
            width: 35px;
            height: 35px;
            font-size: 16px;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-left: auto;
        }
        
        .config-btn:hover {
            background: rgba(255, 255, 255, 0.3);
            transform: scale(1.1);
        }

        @media (max-width: 480px) {
            .control-grid {
                grid-template-columns: 1fr;
            }
            
            .drawing-tools {
                grid-template-columns: repeat(4, 1fr);
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <div class="title">🎮 沙盘控制器</div>
            <div class="status">
                <span>连接状态:</span>
                <div class="status-indicator" id="status-indicator"></div>
                <span id="status-text">未连接</span>
                <button class="config-btn" onclick="openIPConfig()" title="配置服务器IP">⚙️</button>
            </div>
        </div>

        <div class="main-content">
            <!-- 连接控制 -->
            <div class="control-grid">
                <div class="control-section">
                    <div class="section-title">🔗 连接</div>
                    <button class="control-button primary" id="connect-btn">连接服务器</button>
                    <button class="control-button danger" id="disconnect-btn" disabled>断开连接</button>
                </div>

                <div class="control-section">
                    <div class="section-title">🎯 操作</div>
                    <button class="control-button warning" id="clear-btn">清空沙盘</button>
                    <button class="control-button" id="reset-btn">重置视图</button>
                </div>
            </div>

            <!-- 模式切换 -->
            <div class="control-section full-width">
                <div class="section-title">🎯 操作模式</div>
                <div class="mode-switcher">
                    <button class="mode-button active" id="draw-mode-btn" data-mode="draw">🎨 画笔模式</button>
                    <button class="mode-button" id="gallery-mode-btn" data-mode="gallery">📸 画册模式</button>
                </div>
            </div>

            <!-- 绘制工具 -->
            <div class="control-section full-width" id="draw-tools-section">
                <div class="section-title">🎨 绘制工具</div>
                <div class="drawing-tools">
                    <button class="tool-button active" id="pen-tool" data-tool="pen">✏️</button>
                    <button class="tool-button" id="eraser-tool" data-tool="eraser">🧽</button>
                    <button class="tool-button" id="building-tool" data-tool="building">🏢</button>
                    <button class="tool-button" id="tree-tool" data-tool="tree">🌳</button>
                    <button class="tool-button" id="road-tool" data-tool="road">🛣️</button>
                    <button class="tool-button" id="water-tool" data-tool="water">💧</button>
                </div>
            </div>

            <!-- 画册工具 -->
            <div class="control-section full-width" id="gallery-tools-section" style="display: none;">
                <div class="section-title">📸 画册工具</div>
                <div class="gallery-tools">
                    <button class="control-button primary" id="select-image-btn">📁 选择图片</button>
                    <button class="control-button" id="take-photo-btn">📷 拍照</button>
                    <button class="control-button" id="clear-gallery-btn">🗑️清空画册</button>
                </div>
                
                <!-- 图片切换控制 -->
                <div class="gallery-navigation">
                    <button class="control-button" id="prev-image-btn">◀ 上一张</button>
                    <button class="control-button" id="next-image-btn">下一张 ▶</button>
                </div>
                
                <input type="file" id="image-input" accept="image/*" style="display: none;" multiple>
            </div>

            <!-- 绘制设置 -->
            <div class="control-grid">
                <div class="control-section">
                    <div class="section-title">📏 画笔大小</div>
                    <div class="slider-container">
                        <label class="slider-label">大小: <span id="brush-size-value">5</span></label>
                        <input type="range" class="slider" id="brush-size" min="1" max="20" value="5">
                    </div>
                </div>

                <div class="control-section">
                    <div class="section-title">🎭 透明度</div>
                    <div class="slider-container">
                        <label class="slider-label">透明度: <span id="opacity-value">100%</span></label>
                        <input type="range" class="slider" id="opacity" min="10" max="100" value="100">
                    </div>
                </div>
            </div>

            <!-- 虚拟触控板 -->
            <div class="control-section full-width">
                <div class="section-title">📱 虚拟触控板</div>
                <div class="virtual-trackpad" id="virtual-trackpad">
                    <div class="trackpad-cursor" id="trackpad-cursor"></div>
                    <span>在此区域滑动控制大屏画布</span>
                </div>
            </div>

            <!-- 坐标信息 -->
            <div class="control-section full-width">
                <div class="section-title">📍 坐标信息</div>
                <div class="coordinates">
                    <div>X: <span id="coord-x">0</span> | Y: <span id="coord-y">0</span></div>
                    <div>工具: <span id="current-tool">画笔</span></div>
                    <div>操作: <span id="action-type">待命</span></div>
                </div>
            </div>

            <!-- 快捷操作 -->
            <div class="control-section full-width">
                <div class="section-title">⚡ 快捷操作</div>
                <button class="control-button" id="fullscreen-btn">全屏模式</button>
                <button class="control-button" id="screenshot-btn">截图保存</button>
                <button class="control-button" id="share-btn">分享链接</button>
            </div>
        </div>
    </div>

    <script src="js/sandbox.js"></script>
    <script src="js/websocket.js"></script>
    <script src="js/mobile-control.js"></script>
    <script>
        function openIPConfig() {
            window.location.href = 'ip-config.html';
        }
    </script>
</body>
</html>